 /*
  * Copyright (c) 2021, 2023, yishun.cn All rights reserved.
  *
  */
 package cn.shun.controller;

 import cn.hutool.core.util.ObjUtil;
 import cn.shun.dao.CategoryDao;
 import cn.shun.local.LocalUserThreadLocal;
 import cn.shun.model.Category;
 import cn.shun.model.CategoryQuery;
 import cn.shun.model.LocalUser;
 import jakarta.annotation.Resource;
 import lombok.extern.slf4j.Slf4j;
 import org.springframework.web.bind.annotation.*;
 import java.util.List;

 /**
  * <p>Project: sboot_2023-cn.shun.controller-CategoryController
  * <p>Powered by yishun On 2023-04-18 17:21:26
  *
  * @author yishun [2465734101@qq.com]
  * @version 1.0
  * @since 17
  */
 @RestController
 @Slf4j
 @RequestMapping("/api/category")
//Restful Api
 public class CategoryController {

     @Resource
     private CategoryDao categoryDao;

     @GetMapping
     public List<Category> select(CategoryQuery query) {
         //如果前端你不传status，那么我默认查询状态是1的列表
         if (ObjUtil.isEmpty(query.getStatus())) {
             query.setStatus(1);
         }
         return categoryDao.select(query);
     }

     @PostMapping
     public Integer insert(@RequestBody Category category) {
         LocalUser localUser = LocalUserThreadLocal.get();
         category.setLastUpdateBy(localUser.getTel());
         return categoryDao.insert(category);
     }

     @PutMapping
     public Integer update(@RequestBody Category category) {
         category.setLastUpdateBy(LocalUserThreadLocal.get().getTel());
         return categoryDao.update(category);
     }

     @DeleteMapping
     public Integer delete(@RequestParam Integer id) {
         return categoryDao.delete(id);
     }
 }